<?php
/**
 * Created by PhpStorm.
 * User: wodrow
 * Date: 18-12-7
 * Time: 下午6:28
 */

namespace common\models\db;


use common\members\wodrow\tools\Model;
use yii\base\ErrorException;

class UserOperateLog extends \common\models\db\tables\UserOperateLog
{
    /**
     * @throws
     */
    public function doLog()
    {
        if (!$this->created_at){
            $this->created_at = Yii_BT_TIME;
        }
        if (!$this->created_by){
            $this->created_by = \Yii::$app->user->id;
        }
        if (!$this->yii_app_id){
            $this->yii_app_id = \Yii::$app->appinfo->yii2App->id;
        }
        if (!$this->uri){
            $this->uri = \Yii::$app->controller->getRoute();
        }
        if (!$this->ip){
            if (\Yii::$app->user->isInConsole){
                $this->ip = \Yii::$app->user->loginIp;
            }else{
                $this->ip = \Yii::$app->request->userIP;
            }
        }
        if (!$this->save()){
            throw new ErrorException(Model::getModelError($this), 201812071846);
        }
    }
}